<?php
class Cl_UserScrap extends WdkClass 
{
	protected
		/******************************************************/
		//	원본 테이블 정보
		/******************************************************/
		$user_scrap_seq			= 0		,	//	키값
		$fk_user_seq			= 0		,	//	사용자 참조키
		$fk_post_seq			= 0		,	//	금액
		$user_scrap_insert_time	= 0		,	//	등록시간
		$user_scrap_del_flag	= 'F'	,	//	삭제시간
		/******************************************************/
		//	추가 정보
		/******************************************************/
		$bbs_id						= ''	,
		$bbs_name					= ''	,
		$post_title					= ''	,		
		$comment_num				= ''	,	//	
		$user_nick					= 0			,	//	
		$user_nick_str				= ''		,	//		
		$user_icon					= ''		,	//	
		$post_title_str				= ''		,	//	
		$user_scrap_insert_time_str	= ''	;
	
	/**
	 * 	
	 */
	function __construct()
	{
		parent::__construct();
		self::getDbo();
	}
	
	/**
	 *	
	 */
	public function __init($data)
	{
		parent::__init($data);
		self::dformat();
	}
	
	/**
	 *	
	 */
	public function load($user_scrap_seq)
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		self::__init($dbo->cLoad($user_scrap_seq));
	}
	
	/**
	 *	
	 */
	public function loadByPost($post_seq=0, $user_seq=0)
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		self::__init($dbo->cLoadByPost($post_seq, $user_seq));
	}
	
	/**
	 *	
	 */
	public function dformat()
	{
		$this->user_scrap_insert_time_str = parent::timeString($this->user_scrap_insert_time);
	}
	
	/**
	 * 
	 */
	public function autoUpdate($log='')
	{
		if((int)$this->user_scrap_seq > 0)
		{
			$this->update($log);
		}
		else
		{
			$this->insert($log);
		}
	}
	
	/**
	 *	
	 */
	public function insert($log='Insert')
	{
		if($this->fk_post_seq == 0) return;
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		$this->user_scrap_insert_time	= time();
		$this->user_scrap_del_flag		= 'F';
		
		$data = array(	'fk_user_seq'				=>	$this->fk_user_seq,
						'fk_post_seq'				=>	$this->fk_post_seq,
						'user_scrap_insert_time'	=>	$this->user_scrap_insert_time,
						'user_scrap_del_flag'		=>	$this->user_scrap_del_flag
					);
		$this->user_scrap_seq = $dbo->insert($data);
		/******************************************************/
		parent::setBackupData(array_keys($data));
		$this->backup($log);
		/******************************************************/
	}
	
	/**
	 * 
	 */
	public function update($log='update')
	{
		throw new DatabaseDisableException("업데이트 불가능합니다.");
	}
	
	/**
	 * 
	 */
	public function delete($log='delete')
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		$dbo->delete(array("user_scrap_seq = ".$this->user_scrap_seq));
		/******************************************************/
		parent::setBackupData();
		$this->backup($log);
		/******************************************************/
	}
	
	/**
	 *	
	 */
	private function backup($log='')
	{
		/*------------------------------------------------------------*/
		$dbo = self::getDbo();
		/*------------------------------------------------------------*/
		$dbo->log($this->user_scrap_seq, $log, $this->backup_data);
	}
	
	/**
	 * 
	 */
	public function getDbo()
	{
		return Wdk::model(substr(__CLASS__, 3));
	}
}